/*
 * IR_sol.c
 *
 * Created: 10/29/2013 2:40:30 PM
 *  Author: Tim
 */ 

//FYI another "../" is in the solution file include call because these files are contained a directory one step deeper than the standard files
#include "../../src/Epiphany.h"

void setup()
{
	//put all your initializations here
	clockInit();
	usbInit(115200);	//the baud does not matter you just need to choose one
	adcInit();			//can't read from the ADC without this
	RTC_DelayInit();		//can't create RTC delays without calling this first
	
	sei();				//the serial port code is interrupt driven.  We have to have the
}

void loop()
{
		if(delayOver)
		{
			
			RTC_Delay_ms(100); //10Hz means we need to print every 100 mS => 0.1 S

			int16_t conversion = analogRead(0);
	
			float voltage =  (conversion*5/8191.0);
			
			uint8_t i;

			fprintf(&USB_str,"IR Dist = % 2.2f cm\r\n",10.594*pow(voltage,-.93) );	//FYI X-CTU only requires \r to create a new line and carriage return. using \r\n is more propper though.
		}
}
